<!DOCTYPE html>
<html>
<body>

  <div>Tests for frozen user agent working properly as defined by https://github.com/WICG/ua-client-hints</div>
<script>
    if (window.testRunner) {
        testRunner.dumpAsText();
    }

    const userAgent = navigator.userAgent;
    const platform = navigator.platform;
    // Validate the user agent string using the following frozen user agent strings found in content/common/user_agent.h:
    // The version is 999 since that's what content_shell uses. Platform values should match
    // strings defined in third_party/blink/renderer/core/frame/navigator_id.cc.
    const desktopUAPlatformMap = new Map([
      ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/999.0.0.0 Safari/537.36", "Win32"],
      ["Mozilla/5.0 (X11; CrOS x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/999.0.0.0 Safari/537.36", "Linux x86_64"],
      ["Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/999.0.0.0 Safari/537.36", "Linux x86_64"],
      ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/999.0.0.0 Safari/537.36", "MacIntel"]
    ]);
    const mobileUAPlatformMap = new Map([
      ["Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/999.0.0.0 Safari/537.36", "Linux armv81"],
      ["Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/999.0.0.0 Mobile Safari/537.36", "Linux armv81"]
    ]);
    const frozenUserAgents = [
      ...desktopUAPlatformMap.keys(),
      ...mobileUAPlatformMap.keys()
    ];

    document.write("UserAgent should match one of the frozen UA strings: " + frozenUserAgents.includes(userAgent) + "<br>");

    let platformMatchesUserAgent;
    const desktopUAs = Array.from(desktopUAPlatformMap.keys());
    if (desktopUAs.includes(userAgent)) {
      platformMatchesUserAgent = (platform == desktopUAPlatformMap.get(userAgent));
    } else {
      platformMatchesUserAgent = (platform == mobileUAPlatformMap.get(userAgent));
    }

    // Validate navigator.appVersion and navigator.appCodeName
    document.write("Navigator.platform should match the corresponding frozen user agent: " +  platformMatchesUserAgent);
</script>
</body>
</html>
